#include "../include/UIManager.hh"
#include <iostream>
#include <limits>
#include <map>
#include <conio.h> // 添加头文件以支持_getch()函数

// 中英法本地化文本映射
std::map<std::string, std::map<Language, std::string>> localizedTexts = {
    {"WELCOME", {
        {Language::CHINESE, "欢迎使用迷你银行系统"},
        {Language::ENGLISH, "Welcome to Mini Banking System"},
        {Language::FRENCH, "Bienvenue au système bancaire mini"}
    }},
    {"SETTINGS_TITLE", {
        {Language::CHINESE, "===== 设置 ====="},
        {Language::ENGLISH, "===== Settings ====="},
        {Language::FRENCH, "===== Paramètres ====="}
    }},
    {"LANGUAGE_OPTION", {
        {Language::CHINESE, "A. 语言设置 (当前: 中文)"},
        {Language::ENGLISH, "A. Language Setting (Current: English)"},
        {Language::FRENCH, "A. Paramètre de langue (Actuel: Français)"}
    }},
    {"ROLE_OPTION", {
        {Language::CHINESE, "B. 角色选择"},
        {Language::ENGLISH, "B. Role Selection"},
        {Language::FRENCH, "B. Sélection de rôle"}
    }},
    {"BACK_OPTION", {
        {Language::CHINESE, "C. 返回主菜单"},
        {Language::ENGLISH, "C. Back to Main Menu"},
        {Language::FRENCH, "C. Retour au menu principal"}
    }},
    {"MAIN_MENU_TITLE", {
        {Language::CHINESE, "===== 银行系统 ====="},
        {Language::ENGLISH, "===== Banking System ====="},
        {Language::FRENCH, "===== Système Bancaire ====="}
    }},
    {"LOGIN_TITLE", {
        {Language::CHINESE, "登录界面"},
        {Language::ENGLISH, "Login"},
        {Language::FRENCH, "Connexion"}
    }},
    {"REGISTER_NEW", {
        {Language::CHINESE, "注册新客户"},
        {Language::ENGLISH, "Register New Customer"},
        {Language::FRENCH, "Enregistrer un nouveau client"}
    }},
    {"LOGIN_EXISTING", {
        {Language::CHINESE, "登录已有账户"},
        {Language::ENGLISH, "Login to Existing Account"},
        {Language::FRENCH, "Se connecter à un compte existant"}
    }},
    {"SETTINGS", {
        {Language::CHINESE, "设置"},
        {Language::ENGLISH, "Settings"},
        {Language::FRENCH, "Paramètres"}
    }},
    {"ENTER_PASSWORD", {
        {Language::CHINESE, "请输入密码: "},
        {Language::ENGLISH, "Please enter password: "},
        {Language::FRENCH, "Veuillez entrer le mot de passe: "}
    }},
    {"LOGIN_SUCCESS", {
        {Language::CHINESE, "登录成功！"},
        {Language::ENGLISH, "Login successful!"},
        {Language::FRENCH, "Connexion réussie!"}
    }},
    {"LOGIN_FAILED", {
        {Language::CHINESE, "登录失败，用户名或密码错误。"},
        {Language::ENGLISH, "Login failed, incorrect username or password."},
        {Language::FRENCH, "Échec de la connexion, nom d'utilisateur ou mot de passe incorrect."}
    }},
    {"REGISTER_CUSTOMER", {
        {Language::CHINESE, "A. 注册新客户"},
        {Language::ENGLISH, "A. Register New Customer"},
        {Language::FRENCH, "A. Enregistrer un nouveau client"}
    }},
    {"ACCESS_CUSTOMER", {
        {Language::CHINESE, "B. 访问客户账户"},
        {Language::ENGLISH, "B. Access Customer Account"},
        {Language::FRENCH, "B. Accéder au compte client"}
    }},
    {"TRANSACTION_REPORT", {
        {Language::CHINESE, "C. 交易报告"},
        {Language::ENGLISH, "C. Transaction Reports"},
        {Language::FRENCH, "C. Rapports de transaction"}
    }},
    {"EXIT", {
        {Language::CHINESE, "D. 退出"},
        {Language::ENGLISH, "D. Exit"},
        {Language::FRENCH, "D. Quitter"}
    }},
    {"CUSTOMER_MANAGEMENT", {
        {Language::CHINESE, "A. 客户管理"},
        {Language::ENGLISH, "A. Customer Management"},
        {Language::FRENCH, "A. Gestion des clients"}
    }},
    {"ACCOUNT_MANAGEMENT", {
        {Language::CHINESE, "B. 账户管理"},
        {Language::ENGLISH, "B. Account Management"},
        {Language::FRENCH, "B. Gestion des comptes"}
    }},
    {"TRANSACTION_MANAGEMENT", {
        {Language::CHINESE, "C. 交易处理"},
        {Language::ENGLISH, "C. Transaction Processing"},
        {Language::FRENCH, "C. Traitement des transactions"}
    }},
    {"USER_MANAGEMENT", {
        {Language::CHINESE, "A. 用户管理"},
        {Language::ENGLISH, "A. User Management"},
        {Language::FRENCH, "A. Gestion des utilisateurs"}
    }},
    {"VIEW_ALL_TRANSACTIONS", {
        {Language::CHINESE, "B. 查看所有交易记录"},
        {Language::ENGLISH, "B. View All Transactions"},
        {Language::FRENCH, "B. Voir toutes les transactions"}
    }},
    {"GENERATE_QUARTERLY_REPORT", {
        {Language::CHINESE, "C. 生成季度报告"},
        {Language::ENGLISH, "C. Generate Quarterly Report"},
        {Language::FRENCH, "C. Générer un rapport trimestriel"}
    }},
    {"SYSTEM_SETTINGS", {
        {Language::CHINESE, "D. 系统设置"},
        {Language::ENGLISH, "D. System Settings"},
        {Language::FRENCH, "D. Paramètres du système"}
    }},
    {"AUDITOR_VIEW_REPORTS", {
        {Language::CHINESE, "A. 查看交易报告"},
        {Language::ENGLISH, "A. View Transaction Reports"},
        {Language::FRENCH, "A. Voir les rapports de transaction"}
    }},
    {"AUDITOR_VIEW_QUARTERLY", {
        {Language::CHINESE, "B. 查看季度报告"},
        {Language::ENGLISH, "B. View Quarterly Reports"},
        {Language::FRENCH, "B. Voir les rapports trimestriels"}
    }},
    {"AUDITOR_GENERATE_AUDIT", {
        {Language::CHINESE, "C. 生成审计报告"},
        {Language::ENGLISH, "C. Generate Audit Report"},
        {Language::FRENCH, "C. Générer un rapport d'audit"}
    }},
    {"PRESS_ENTER", {
        {Language::CHINESE, "按回车键继续..."},
        {Language::ENGLISH, "Press Enter to continue..."},
        {Language::FRENCH, "Appuyez sur Entrée pour continuer..."}
    }},
    {"PLEASE_SELECT", {
        {Language::CHINESE, "请按键选择"},
        {Language::ENGLISH, "Please select"},
        {Language::FRENCH, "Veuillez sélectionner"}
    }},
    {"ACCOUNTS_MENU", {
        {Language::CHINESE, "1. 访问储蓄账户"},
        {Language::ENGLISH, "1. Access Savings Account"},
        {Language::FRENCH, "1. Accéder au compte d'épargne"}
    }},
    {"CHECKING_ACCOUNT", {
        {Language::CHINESE, "2. 访问支票账户"},
        {Language::ENGLISH, "2. Access Checking Account"},
        {Language::FRENCH, "2. Accéder au compte courant"}
    }},
    {"VIEW_ALL_TRANSACTIONS_CUSTOMER", {
        {Language::CHINESE, "3. 查看所有交易"},
        {Language::ENGLISH, "3. View All Transactions"},
        {Language::FRENCH, "3. Voir toutes les transactions"}
    }},
    {"GENERATE_CUSTOMER_REPORT", {
        {Language::CHINESE, "4. 生成客户报告"},
        {Language::ENGLISH, "4. Generate Customer Report"},
        {Language::FRENCH, "4. Générer un rapport client"}
    }},
    {"RETURN_TO_MAIN_MENU", {
        {Language::CHINESE, "5. 返回主菜单"},
        {Language::ENGLISH, "5. Return to Main Menu"},
        {Language::FRENCH, "5. Retourner au menu principal"}
    }},
    {"CUSTOMER_ROLE", {
        {Language::CHINESE, "客户"},
        {Language::ENGLISH, "Customer"},
        {Language::FRENCH, "Client"}
    }},
    {"EMPLOYEE_ROLE", {
        {Language::CHINESE, "员工"},
        {Language::ENGLISH, "Employee"},
        {Language::FRENCH, "Employé"}
    }},
    {"ADMIN_ROLE", {
        {Language::CHINESE, "管理员"},
        {Language::ENGLISH, "Administrator"},
        {Language::FRENCH, "Administrateur"}
    }},
    {"AUDITOR_ROLE", {
        {Language::CHINESE, "审计员"},
        {Language::ENGLISH, "Auditor"},
        {Language::FRENCH, "Auditeur"}
    }},
    {"NOT_LOGGED_IN", {
        {Language::CHINESE, "未登录"},
        {Language::ENGLISH, "Not logged in"},
        {Language::FRENCH, "Non connecté"}
    }},
    {"ROLE_SELECTION", {
        {Language::CHINESE, "角色选择:"},
        {Language::ENGLISH, "Role Selection:"},
        {Language::FRENCH, "Sélection de rôle:"}
    }},
    {"CUSTOMER_DEFAULT", {
        {Language::CHINESE, "A. 客户 (默认)"},
        {Language::ENGLISH, "A. Customer (Default)"},
        {Language::FRENCH, "A. Client (Par défaut)"}
    }},
    {"EMPLOYEE_KEY", {
        {Language::CHINESE, "B. 员工 (需要秘钥)"},
        {Language::ENGLISH, "B. Employee (Requires key)"},
        {Language::FRENCH, "B. Employé (Nécessite une clé)"}
    }},
    {"ADMIN_KEY", {
        {Language::CHINESE, "C. 管理员 (需要秘钥)"},
        {Language::ENGLISH, "C. Administrator (Requires key)"},
        {Language::FRENCH, "C. Administrateur (Nécessite une clé)"}
    }},
    {"AUDITOR_KEY", {
        {Language::CHINESE, "D. 审计员 (需要秘钥)"},
        {Language::ENGLISH, "D. Auditor (Requires key)"},
        {Language::FRENCH, "D. Auditeur (Nécessite une clé)"}
    }},
    {"ENTER_USERNAME", {
        {Language::CHINESE, "请输入用户名: "},
        {Language::ENGLISH, "Please enter username: "},
        {Language::FRENCH, "Veuillez entrer le nom d'utilisateur: "}
    }},
    {"ENTER_KEY", {
        {Language::CHINESE, "请输入秘钥: "},
        {Language::ENGLISH, "Please enter key: "},
        {Language::FRENCH, "Veuillez entrer la clé: "}
    }},
    {"AUTH_SUCCESS", {
        {Language::CHINESE, "身份验证成功！"},
        {Language::ENGLISH, "Authentication successful!"},
        {Language::FRENCH, "Authentification réussie!"}
    }},
    {"LANG_SETTING", {
        {Language::CHINESE, "语言设置 / Language Setting / Paramètre de langue:"},
        {Language::ENGLISH, "Language Setting / 语言设置 / Paramètre de langue:"},
        {Language::FRENCH, "Paramètre de langue / 语言设置 / Language Setting:"}
    }},
    {"CHINESE_LANG", {
        {Language::CHINESE, "A. 中文"},
        {Language::ENGLISH, "A. Chinese (中文)"},
        {Language::FRENCH, "A. Chinois (中文)"}
    }},
    {"ENGLISH_LANG", {
        {Language::CHINESE, "B. 英语"},
        {Language::ENGLISH, "B. English"},
        {Language::FRENCH, "B. Anglais (English)"}
    }},
    {"FRENCH_LANG", {
        {Language::CHINESE, "C. 欧元"},
        {Language::ENGLISH, "C. EUR (Euro)"},
        {Language::FRENCH, "C. EUR (Euro)"}
    }},
    {"SWITCHED_CHINESE", {
        {Language::CHINESE, "已切换到中文界面。"},
        {Language::ENGLISH, "Switched to Chinese interface."},
        {Language::FRENCH, "Passé à l'interface chinoise."}
    }},
    {"SWITCHED_ENGLISH", {
        {Language::CHINESE, "已切换到英语界面。"},
        {Language::ENGLISH, "Switched to English interface."},
        {Language::FRENCH, "Passé à l'interface anglaise."}
    }},
    {"SWITCHED_FRENCH", {
        {Language::CHINESE, "已切换到欧元界面"},
        {Language::ENGLISH, "Switched to EUR (Euro) interface"},
        {Language::FRENCH, "Interface changée en EUR (Euro)"}
    }}
    // 可以继续添加更多本地化文本...
};

UIManager::UIManager(AuthManager& auth, Language defaultLanguage)
    : authManager(auth), currentLanguage(defaultLanguage) {
}

void UIManager::setLanguage(Language lang) {
    currentLanguage = lang;
}

Language UIManager::getCurrentLanguage() const {
    return currentLanguage;
}

std::string UIManager::getLocalizedText(const std::string& key) const {
    if (localizedTexts.find(key) != localizedTexts.end()) {
        if (localizedTexts[key].find(currentLanguage) != localizedTexts[key].end()) {
            return localizedTexts[key][currentLanguage];
        }
    }
    return key; // 如果找不到对应的本地化文本，返回原始key
}

char UIManager::getKeyChoice(const std::string& validKeys) const {
    std::string promptText;
    if (currentLanguage == Language::ENGLISH) {
        promptText = "Press a key to select (" + validKeys + "): ";
    } else if (currentLanguage == Language::FRENCH) {
        promptText = "Appuyez sur une touche pour sélectionner (" + validKeys + "): ";
    } else {
        promptText = "请按键选择 (" + validKeys + "): ";
    }
    
    std::cout << promptText;
    
    char key;
    
    while (true) {
        // 使用_getch()获取按键，不需要按Enter键
        key = _toupper(_getch());
        
        // 检查是否在有效范围内
        if (validKeys.find(key) != std::string::npos) {
            // 输出选择以便用户确认
            std::cout << key << std::endl;
            break;
        }
    }
    
    return key;
}

void UIManager::showSettingsMenu() {
    while (true) {
        std::cout << std::endl;
        std::cout << getLocalizedText("SETTINGS_TITLE") << std::endl;
        std::cout << getLocalizedText("LANGUAGE_OPTION") << std::endl;
        
        // 获取当前角色的本地化文本
        std::string roleText;
        if (authManager.isAuthenticated()) {
            switch (authManager.getCurrentUserRole()) {
                case Role::CUSTOMER:
                    roleText = getLocalizedText("CUSTOMER_ROLE");
                    break;
                case Role::EMPLOYEE:
                    roleText = getLocalizedText("EMPLOYEE_ROLE");
                    break;
                case Role::ADMIN:
                    roleText = getLocalizedText("ADMIN_ROLE");
                    break;
                case Role::AUDITOR:
                    roleText = getLocalizedText("AUDITOR_ROLE");
                    break;
            }
        } else {
            roleText = getLocalizedText("NOT_LOGGED_IN");
        }
        
        std::cout << getLocalizedText("ROLE_OPTION") << " (" << roleText << ")" << std::endl;
        std::cout << getLocalizedText("BACK_OPTION") << std::endl;
        
        char choice = getKeyChoice("ABC");
        
        switch (choice) {
            case 'A': // 语言设置
                std::cout << std::endl;
                std::cout << getLocalizedText("LANG_SETTING") << std::endl;
                std::cout << getLocalizedText("CHINESE_LANG") << std::endl;
                std::cout << getLocalizedText("ENGLISH_LANG") << std::endl;
                std::cout << getLocalizedText("FRENCH_LANG") << std::endl;
                
                choice = getKeyChoice("ABC");
                if (choice == 'A') {
                    setLanguage(Language::CHINESE);
                    std::cout << getLocalizedText("SWITCHED_CHINESE") << std::endl;
                } else if (choice == 'B') {
                    setLanguage(Language::ENGLISH);
                    std::cout << getLocalizedText("SWITCHED_ENGLISH") << std::endl;
                } else {
                    setLanguage(Language::FRENCH);
                    std::cout << getLocalizedText("SWITCHED_FRENCH") << std::endl;
                }
                break;
                
            case 'B': { // 角色选择
                std::cout << std::endl;
                std::cout << getLocalizedText("ROLE_SELECTION") << std::endl;
                std::cout << getLocalizedText("CUSTOMER_DEFAULT") << std::endl;
                std::cout << getLocalizedText("EMPLOYEE_KEY") << std::endl;
                std::cout << getLocalizedText("ADMIN_KEY") << std::endl;
                std::cout << getLocalizedText("AUDITOR_KEY") << std::endl;
                
                choice = getKeyChoice("ABCD");
                std::string username, password;
                
                std::cout << getLocalizedText("ENTER_USERNAME");
                username = getInput("");
                
                bool authSuccess = false;
                
                switch (choice) {
                    case 'A': // 客户 - 现在也需要密码
                        std::cout << getLocalizedText("ENTER_PASSWORD");
                        password = getPassword("");
                        authSuccess = authManager.authenticateAsCustomer(username, password);
                        break;
                    case 'B': // 员工
                        std::cout << getLocalizedText("ENTER_KEY");
                        password = getPassword("");
                        authSuccess = authManager.authenticateAsEmployee(username, password);
                        break;
                    case 'C': // 管理员
                        std::cout << getLocalizedText("ENTER_KEY");
                        password = getPassword("");
                        authSuccess = authManager.authenticateAsAdmin(username, password);
                        break;
                    case 'D': // 审计员
                        std::cout << getLocalizedText("ENTER_KEY");
                        password = getPassword("");
                        authSuccess = authManager.authenticateAsAuditor(username, password);
                        break;
                }
                
                if (authSuccess) {
                    std::cout << getLocalizedText("AUTH_SUCCESS") << std::endl;
                    return; // 返回到调用此函数的地方
                }
                break;
            }
                
            case 'C': // 返回主菜单
                return;
        }
    }
}

void UIManager::showMainMenu() {
    // 主菜单显示逻辑
    std::cout << std::endl;
    std::cout << getLocalizedText("MAIN_MENU_TITLE") << std::endl;
    
    // 根据用户角色显示不同的菜单
    switch (authManager.getCurrentUserRole()) {
        case Role::CUSTOMER:
            showCustomerMenu();
            break;
        case Role::EMPLOYEE:
            showEmployeeMenu();
            break;
        case Role::ADMIN:
            showAdminMenu();
            break;
        case Role::AUDITOR:
            showAuditorMenu();
            break;
    }
}

void UIManager::showCustomerMenu() {
    std::cout << getLocalizedText("REGISTER_CUSTOMER") << std::endl;
    std::cout << getLocalizedText("ACCESS_CUSTOMER") << std::endl;
    std::cout << getLocalizedText("TRANSACTION_REPORT") << std::endl;
    std::cout << getLocalizedText("EXIT") << std::endl;
}

void UIManager::showEmployeeMenu() {
    std::cout << getLocalizedText("CUSTOMER_MANAGEMENT") << std::endl;
    std::cout << getLocalizedText("ACCOUNT_MANAGEMENT") << std::endl;
    std::cout << getLocalizedText("TRANSACTION_MANAGEMENT") << std::endl;
    std::cout << getLocalizedText("EXIT") << std::endl;
}

void UIManager::showAdminMenu() {
    std::cout << getLocalizedText("USER_MANAGEMENT") << std::endl;
    std::cout << getLocalizedText("VIEW_ALL_TRANSACTIONS") << std::endl;
    std::cout << getLocalizedText("GENERATE_QUARTERLY_REPORT") << std::endl;
    std::cout << getLocalizedText("SYSTEM_SETTINGS") << std::endl;
    std::cout << "E. " << getLocalizedText("ACCOUNT_MANAGEMENT") << std::endl;
    std::cout << getLocalizedText("EXIT") << std::endl;
}

void UIManager::showAuditorMenu() {
    std::cout << getLocalizedText("AUDITOR_VIEW_REPORTS") << std::endl;
    std::cout << getLocalizedText("AUDITOR_VIEW_QUARTERLY") << std::endl;
    std::cout << getLocalizedText("AUDITOR_GENERATE_AUDIT") << std::endl;
    std::cout << getLocalizedText("EXIT") << std::endl;
}

void UIManager::showCustomerAccountsMenu(const std::string& customerName) {
    std::string title;
    std::string customerAccounts;
    
    if (currentLanguage == Language::ENGLISH) {
        title = "===== Customer: " + customerName + " =====";
        customerAccounts = "This customer has the following accounts:";
    } else if (currentLanguage == Language::FRENCH) {
        title = "===== Client: " + customerName + " =====";
        customerAccounts = "Ce client a les comptes suivants:";
    } else {
        title = "===== 客户: " + customerName + " =====";
        customerAccounts = "该客户有以下账户:";
    }
    
    std::cout << title << std::endl;
    std::cout << customerAccounts << std::endl;
    std::cout << std::endl;
    
    // 使用本地化文本 - 确保只有一个储蓄账户和一个支票账户选项
    std::cout << getLocalizedText("ACCOUNTS_MENU") << std::endl;
    std::cout << getLocalizedText("CHECKING_ACCOUNT") << std::endl;
    std::cout << getLocalizedText("VIEW_ALL_TRANSACTIONS_CUSTOMER") << std::endl;
    std::cout << getLocalizedText("GENERATE_CUSTOMER_REPORT") << std::endl;
    std::cout << getLocalizedText("RETURN_TO_MAIN_MENU") << std::endl;
}

void UIManager::showAccountMenu(const std::string& accountId) {
    // 本地化账户菜单
    std::string title;
    if (currentLanguage == Language::ENGLISH) {
        title = "===== Bank Account: " + accountId + " =====";
    } else if (currentLanguage == Language::FRENCH) {
        title = "===== Compte Bancaire: " + accountId + " =====";
    } else {
        title = "===== 银行账户: " + accountId + " =====";
    }
    
    std::cout << title << std::endl;
    
    // 使用数字菜单选择
    if (currentLanguage == Language::ENGLISH) {
        std::cout << "1. Deposit" << std::endl;
        std::cout << "2. Withdraw" << std::endl;
        std::cout << "3. Transfer" << std::endl;
        std::cout << "4. Currency Exchange" << std::endl;
        std::cout << "5. View Transaction History" << std::endl;
        std::cout << "6. Generate Account Report" << std::endl;
        std::cout << "7. Return to Customer Page" << std::endl;
    } else if (currentLanguage == Language::FRENCH) {
        std::cout << "1. Dépôt" << std::endl;
        std::cout << "2. Retrait" << std::endl;
        std::cout << "3. Transfert" << std::endl;
        std::cout << "4. Échange de devises" << std::endl;
        std::cout << "5. Voir l'historique des transactions" << std::endl;
        std::cout << "6. Générer un rapport de compte" << std::endl;
        std::cout << "7. Retourner à la page client" << std::endl;
    } else {
        std::cout << "1. 存款" << std::endl;
        std::cout << "2. 取款" << std::endl;
        std::cout << "3. 转账" << std::endl;
        std::cout << "4. 货币兑换" << std::endl;
        std::cout << "5. 查看交易历史" << std::endl;
        std::cout << "6. 生成账户报告" << std::endl;
        std::cout << "7. 返回客户页面" << std::endl;
    }
}

void UIManager::showDepositMenu(const std::string& accountId) {
    // 本地化存款界面
    std::string title;
    std::string balanceLabel;
    std::string amountPrompt;
    std::string notePrompt;
    std::string currencyPrompt;
    
    if (currentLanguage == Language::ENGLISH) {
        title = "===== Deposit to Account: " + accountId + " =====";
        balanceLabel = "Current Balance:";
        amountPrompt = "Please enter deposit amount: ";
        notePrompt = "Add note (optional): ";
        currencyPrompt = "Select currency for deposit:";
    } else if (currentLanguage == Language::FRENCH) {
        title = "===== Dépôt sur compte: " + accountId + " =====";
        balanceLabel = "Solde actuel:";
        amountPrompt = "Veuillez entrer le montant du dépôt: ";
        notePrompt = "Ajouter une note (facultatif): ";
        currencyPrompt = "Sélectionnez la devise pour le dépôt:";
    } else {
        title = "===== 存款到账户: " + accountId + " =====";
        balanceLabel = "当前余额:";
        amountPrompt = "请输入存款金额: ";
        notePrompt = "添加备注 (可选): ";
        currencyPrompt = "请选择存款货币:";
    }
    
    std::cout << title << std::endl;
    std::cout << balanceLabel << std::endl;
    // 余额信息将在BankSystem中显示
    std::cout << std::endl;
    
    std::cout << currencyPrompt << std::endl;
    std::cout << "A. CNY (人民币 ¥)" << std::endl;
    std::cout << "B. USD (美元 $)" << std::endl;
    std::cout << "C. EUR (欧元 €)" << std::endl;
    
    std::cout << amountPrompt;
    std::cout << notePrompt;
}

void UIManager::showWithdrawMenu(const std::string& accountId) {
    // 本地化取款界面
    std::string title;
    std::string balanceLabel;
    std::string amountPrompt;
    std::string notePrompt;
    std::string currencyPrompt;
    
    if (currentLanguage == Language::ENGLISH) {
        title = "===== Withdraw from Account: " + accountId + " =====";
        balanceLabel = "Current Balance:";
        amountPrompt = "Please enter withdrawal amount: ";
        notePrompt = "Add note (optional): ";
        currencyPrompt = "Select currency for withdrawal:";
    } else if (currentLanguage == Language::FRENCH) {
        title = "===== Retrait du compte: " + accountId + " =====";
        balanceLabel = "Solde actuel:";
        amountPrompt = "Veuillez entrer le montant du retrait: ";
        notePrompt = "Ajouter une note (facultatif): ";
        currencyPrompt = "Sélectionnez la devise pour le retrait:";
    } else {
        title = "===== 从账户取款: " + accountId + " =====";
        balanceLabel = "当前余额:";
        amountPrompt = "请输入取款金额: ";
        notePrompt = "添加备注 (可选): ";
        currencyPrompt = "请选择取款货币:";
    }
    
    std::cout << title << std::endl;
    std::cout << balanceLabel << std::endl;
    // 余额信息将在BankSystem中显示
    std::cout << std::endl;
    
    std::cout << currencyPrompt << std::endl;
    std::cout << "A. CNY (人民币 ¥)" << std::endl;
    std::cout << "B. USD (美元 $)" << std::endl;
    std::cout << "C. EUR (欧元 €)" << std::endl;
    
    std::cout << amountPrompt;
    std::cout << notePrompt;
}

void UIManager::showTransferMenu(const std::string& accountId) {
    // 本地化转账界面
    std::string title;
    std::string balanceLabel;
    std::string destPrompt;
    std::string amountPrompt;
    std::string notePrompt;
    std::string currencyPrompt;
    
    if (currentLanguage == Language::ENGLISH) {
        title = "===== Transfer from Account: " + accountId + " =====";
        balanceLabel = "Current Balance:";
        destPrompt = "Please enter destination account ID: ";
        amountPrompt = "Please enter transfer amount: ";
        notePrompt = "Add note (optional): ";
        currencyPrompt = "Select currency for transfer:";
    } else if (currentLanguage == Language::FRENCH) {
        title = "===== Transfert depuis le compte: " + accountId + " =====";
        balanceLabel = "Solde actuel:";
        destPrompt = "Veuillez entrer l'ID du compte de destination: ";
        amountPrompt = "Veuillez entrer le montant du transfert: ";
        notePrompt = "Ajouter une note (facultatif): ";
        currencyPrompt = "Sélectionnez la devise pour le transfert:";
    } else {
        title = "===== 从账户转账: " + accountId + " =====";
        balanceLabel = "当前余额:";
        destPrompt = "请输入目标账户ID: ";
        amountPrompt = "请输入转账金额: ";
        notePrompt = "添加备注 (可选): ";
        currencyPrompt = "请选择转账货币:";
    }
    
    std::cout << title << std::endl;
    std::cout << balanceLabel << std::endl;
    // 余额信息将在BankSystem中显示
    std::cout << std::endl;
    
    std::cout << destPrompt;
    
    std::cout << currencyPrompt << std::endl;
    std::cout << "A. CNY (人民币 ¥)" << std::endl;
    std::cout << "B. USD (美元 $)" << std::endl;
    std::cout << "C. EUR (欧元 €)" << std::endl;
    
    std::cout << amountPrompt;
    std::cout << notePrompt;
}

void UIManager::showTransactionReportsMenu() {
    // 本地化交易报告菜单
    std::string title;
    
    if (currentLanguage == Language::ENGLISH) {
        title = "===== Transaction Reports =====";
        std::cout << title << std::endl;
        std::cout << "1. Generate Global Transaction Report" << std::endl;
        std::cout << "2. Generate Customer Transaction Report" << std::endl;
        std::cout << "3. Generate Account Transaction Report" << std::endl;
        std::cout << "4. Return to Main Menu" << std::endl;
    } else if (currentLanguage == Language::FRENCH) {
        title = "===== Rapports de transaction =====";
        std::cout << title << std::endl;
        std::cout << "1. Générer un rapport de transaction global" << std::endl;
        std::cout << "2. Générer un rapport de transaction client" << std::endl;
        std::cout << "3. Générer un rapport de transaction de compte" << std::endl;
        std::cout << "4. Retourner au menu principal" << std::endl;
    } else {
        title = "===== 交易报告 =====";
        std::cout << title << std::endl;
    std::cout << "1. 生成全局交易报告" << std::endl;
    std::cout << "2. 生成客户交易报告" << std::endl;
    std::cout << "3. 生成账户交易报告" << std::endl;
    std::cout << "4. 返回主菜单" << std::endl;
    }
}

void UIManager::showCurrencyExchangeMenu(const std::string& accountId) {
    // 本地化货币兑换界面
    std::string title;
    std::string balanceLabel;
    std::string fromPrompt;
    std::string toPrompt;
    std::string amountPrompt;
    std::string feePrompt;
    std::string notePrompt;
    
    if (currentLanguage == Language::ENGLISH) {
        title = "===== Currency Exchange for Account: " + accountId + " =====";
        balanceLabel = "Current Balances:";
        fromPrompt = "Select source currency:";
        toPrompt = "Select target currency:";
        amountPrompt = "Please enter exchange amount: ";
        feePrompt = "Note: A 1% fee will be charged for currency exchange.";
        notePrompt = "Add note (optional): ";
    } else if (currentLanguage == Language::FRENCH) {
        title = "===== Échange de devises pour le compte: " + accountId + " =====";
        balanceLabel = "Soldes actuels:";
        fromPrompt = "Sélectionnez la devise source:";
        toPrompt = "Sélectionnez la devise cible:";
        amountPrompt = "Veuillez entrer le montant de l'échange: ";
        feePrompt = "Remarque: Des frais de 1% seront facturés pour l'échange de devises.";
        notePrompt = "Ajouter une note (facultatif): ";
    } else {
        title = "===== 账户货币兑换: " + accountId + " =====";
        balanceLabel = "当前余额:";
        fromPrompt = "请选择源货币:";
        toPrompt = "请选择目标货币:";
        amountPrompt = "请输入兑换金额: ";
        feePrompt = "注意：货币兑换将收取1%的手续费。";
        notePrompt = "添加备注 (可选): ";
    }
    
    std::cout << title << std::endl;
    std::cout << balanceLabel << std::endl;
    // 余额信息将在BankSystem中显示
    std::cout << std::endl;
    
    std::cout << fromPrompt << std::endl;
    std::cout << "A. CNY (人民币 ¥)" << std::endl;
    std::cout << "B. USD (美元 $)" << std::endl;
    std::cout << "C. EUR (欧元 €)" << std::endl;
    
    std::cout << toPrompt << std::endl;
    std::cout << "A. CNY (人民币 ¥)" << std::endl;
    std::cout << "B. USD (美元 $)" << std::endl;
    std::cout << "C. EUR (欧元 €)" << std::endl;
    
    std::cout << amountPrompt;
    std::cout << feePrompt << std::endl;
    std::cout << notePrompt;
}

void UIManager::displayMessage(const std::string& message) const {
    std::cout << message << std::endl;
}

std::string UIManager::getInput(const std::string& prompt) const {
    if (!prompt.empty()) {
        std::cout << prompt;
    }
    
    // 检查是否是请求按回车键继续的提示
    if (prompt == getLocalizedText("PRESS_ENTER") || 
        prompt.find("按回车键继续") != std::string::npos || 
        prompt.find("Press Enter to continue") != std::string::npos || 
        prompt.find("Appuyez sur Entrée pour continuer") != std::string::npos) {
        // 如果是请求按回车键继续，直接用_getch()等待任意键
        _getch();
        return "";
    }
    
    // 检查是否是密码输入提示
    if (prompt.find("密码") != std::string::npos || 
        prompt.find("password") != std::string::npos || 
        prompt.find("mot de passe") != std::string::npos ||
        prompt == getLocalizedText("ENTER_PASSWORD")) {
        // 如果是密码输入，使用getPassword方法处理
        return getPassword(prompt);
    }
    
    // 其他情况仍然使用getline
    std::string input;
    std::getline(std::cin, input);
    return input;
}

int UIManager::getMenuChoice(int minOption, int maxOption) const {
    std::string promptText;
    if (currentLanguage == Language::ENGLISH) {
        promptText = "Press a key to select (" + std::to_string(minOption) + "-" + std::to_string(maxOption) + "): ";
    } else if (currentLanguage == Language::FRENCH) {
        promptText = "Appuyez sur une touche pour sélectionner (" + std::to_string(minOption) + "-" + std::to_string(maxOption) + "): ";
    } else {
        promptText = "请按键选择 (" + std::to_string(minOption) + "-" + std::to_string(maxOption) + "): ";
    }
    
    std::cout << promptText;
    
    char key;
    int choice;
    
    while (true) {
        // 使用_getch()获取按键，不需要按Enter键
        key = _getch();
        
        // 将字符转换为数字
        choice = key - '0';
        
        // 检查是否在有效范围内
        if (choice >= minOption && choice <= maxOption) {
            // 输出选择以便用户确认
            std::cout << choice << std::endl;
            break;
        }
    }
    
    return choice;
}

// 六位密码输入方法
std::string UIManager::getPassword(const std::string& prompt) const {
    if (!prompt.empty()) {
        std::cout << prompt;
    }
    
    std::string password;
    char ch;
    
    while (true) {
        ch = _getch(); // 无回显获取字符
        
        // 处理退格键
        if (ch == '\b' && !password.empty()) {
            password.pop_back();
            std::cout << "\b \b"; // 退格，打空格，再退格
            continue;
        }
        
        // 按Enter键且密码长度为6位时完成输入
        if (ch == '\r' && password.length() == 6) {
            break;
        }
        
        // 只接受数字输入且密码长度不超过6位
        if (ch >= '0' && ch <= '9' && password.length() < 6) {
            password += ch;
            std::cout << "*"; // 显示星号
        }
    }
    
    std::cout << std::endl; // 密码输入完成后换行
    return password;
} 